﻿<%@ Page language="vb" Inherits="Mysoft.Map.Web.Controls.Lookup.LookupMultiPage" CodeBehind="Mysoft.Map.Application.Components.dll" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<html>
<head>
<title>查找记录</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8"/>
<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
<link rel="stylesheet" type="text/css" href="/_common/styles/dialogs.css">
<script language="javascript" src="/_controls/settings.aspx"></script>
<script language="javascript" src="/_forms/addrelated.js"></script>
<script language="javascript" src="/_controls/util/util.js"></script>
<script language="javascript" src="/_controls/number/number.js"></script>

<link rel="stylesheet" type="text/css" href="/_common/styles/select.css">
<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
<script language="javascript" src="/_controls/util/util.js"></script>
<script language="javascript" src="/_common/scripts/global.js"></script>

	<link rel="stylesheet" type="text/css" href="/_controls/lookup/lookupdialogs.css">
	<script language="javascript" src="/_controls/lookup/map_lookupdialogs.js"></script>
	
		<link rel="stylesheet" type="text/css" href="/_grid/map_grid.css">
		<link rel="stylesheet" type="text/css" href="/_controls/find/find.css">
		<link rel="stylesheet" type="text/css" href="/_controls/tree/gridtree.css">
	
	<script language="JavaScript">
<%
		RenderCreatePrivileges()
%>	
		_mode = <%=CType(Mode, Integer)%>;

<%
		Dim strRowsLimit As String
		strRowsLimit = Trim(Request.QueryString("rowslimit"))
		If IsNumeric(strRowsLimit) Then
			Response.Write("_rowslimit = " & CInt(strRowsLimit) & ";")
		Else
			Response.Write("_rowslimit = 0;")
		End If
%>

		function applychanges()
		{
			if (_rowslimit > 0 && tblSelected.rows.length > _rowslimit)
			{
				alert("最多只允许选中 " + _rowslimit + " 条记录，请重新选择！");
				return;
			}
			removeNoOrder();
			window.returnValue = buildReturnValue( tblSelected.rows );
			window.close();
		}
		
		
		function cancel()
		{
			window.close();
		}
	
		function window.onload()
		{ 
			appendExistingItems();
			if ( !checkMode( _mode, LookupBrowse ) )
			{
				findValue.focus();
			}
			refreshNoOrder();
		}
	
		function appendExistingItems()
		{
			var args = this.dialogArguments;
			if ( args == null ) return;
			if ( args.items == null ) return;
			var items = args.items;
			
			var len = items.length;
			for ( var i = 0; i < len; i++ )
			{
				var item = items[i];
				if (item.getAttribute("oid") == "") continue;
				appendItem( item.getAttribute("oid"), item.getAttribute("otype"), item.innerHTML )
			}
			
			setNavigationState();
		}
		
		function resultsReady()
		{
			if ( frmResults.document.readyState == "complete" )
			{
				document.body.style.cursor = "auto";
				
				if ( !checkMode( _mode, LookupBrowse ) )
				{
					btnGo.disabled = false;
				}
			
				setNavigationState();
			}
		}
		
		//	remove the selected items from the right side
		//
		function removeSelected()
		{
			var items = tblSelected.selectedItems;
			for ( var i = 0; i < items.length; i++ )
			{
				items[i].removeNode( true )
			}
			
			//	clear the selected items collection
			//
			items.splice( 0, items.length );
			
			//	make sure that there there is something selected
			//  if there are still items left
			//
			if ( tblSelected.rows.length > 0 )
			{					
				selectItem( tblSelected, tblSelected.rows[0], true );
			}
			refreshNoOrder();
			setNavigationState();
		}
		
		//	check if the entity is already selected
		//
		function duplicateSelection( oid )
		{
			var len = tblSelected.rows.length;
			for ( var i = 0; i < len; i++ )
			{
				if ( tblSelected.rows[i].oid == oid )
				{
					return true;
				}
			}
			return false;
		}
		
		function appendItem( id, type, html )
		{
			var tr		= tblSelected.insertRow();
			tr.oid		= id;
			tr.otype	= type;

			var td	= tr.insertCell();
			td.className	= "sel";
			td.noWrap		= true;
			td.innerHTML	= html;

			if ( tr.rowIndex == 0 )
			{	
				selectItem( tblSelected, tr, false );
			}
		}
		
		//	append all selected items from the left to the right
		//
		function appendSelected()
		{
			if (frmResults.tblResults == undefined)
			{
				return;
			}
			
			var items = frmResults.tblResults.selectedItems;
			if ( items )
			{
				var len	= items.length;

				for ( var i = 0; i < len; i++ )
				{
					var o = items[i];

					//	if this item isn't a duplicate selection then add it
					//
					if ( !duplicateSelection( o.oid ) )
					{
						appendItem( o.oid, o.otype, o.firstChild.innerHTML );
					}
				}
				refreshNoOrder();
				setNavigationState();
			}
		}
		
		//515工作流
		function refreshNoOrder()
		{
		    var intStartOrderNo = 1;
		    var curCell = null;
		    for(var i=0;i<tblSelected.rows.length;i++)
		    {
		        curCell = tblSelected.rows[i].cells[0];
		        curCell.innerHTML = '<span style="text-align:rigth">' + intStartOrderNo +' </span>' + curCell.innerHTML.substr(curCell.innerHTML.indexOf("<IMG"));
		        intStartOrderNo++;
		    }
		}
		//515工作流
		function removeNoOrder()
		{
		    var curCell = null;
		    for(var i=0;i<tblSelected.rows.length;i++)
		    {
		        curCell = tblSelected.rows[i].cells[0];
		        curCell.innerHTML =curCell.innerHTML.substr(curCell.innerHTML.indexOf("<IMG"));
		    }		    
		}
		//515工作流		
		function moveSelected(rowObj,direct)
		{
		    var nextRow = preRow = null;
		    var tmpHtmlString = rowObj.cells[0].innerHTML;
		    if(direct == "down")
		    {
		        nextRow = rowObj.nextSibling;
		        if (nextRow==null) return;
		        rowObj.cells[0].innerHTML = nextRow.cells[0].innerHTML;
		        nextRow.cells[0].innerHTML = tmpHtmlString;
		        unselectItem(tblSelected,rowObj);  
                selectItem(tblSelected,nextRow,true); 		             
		    }
		    else if(direct == "up")
		    {
		        preRow = rowObj.previousSibling;
		        if(preRow==null) return;
		        rowObj.cells[0].innerHTML = preRow.cells[0].innerHTML;
		        preRow.cells[0].innerHTML = tmpHtmlString;
		        unselectItem(tblSelected,rowObj);  
                selectItem(tblSelected,preRow,true);		         		        
		    }	    
		}		
		//515工作流			
        function moveDown()
        {
            var items = tblSelected.selectedItems;
            if(items==undefined) return;
            items.sort(new Function("item1","item2","return parseInt(item1.cells[0].firstChild.innerText) - parseInt(item2.cells[0].firstChild.innerText)"));            
            if (items.length == 0) return;
            for(var i=items.length-1;i>-1;i--)
            {
              moveSelected(items[i],"down");              
            }
            refreshNoOrder();
        }
        //515工作流
        function moveUp()
        {
            var items = tblSelected.selectedItems;
            if(items==undefined) return;
            items.sort(new Function("item1","item2","return parseInt(item2.cells[0].firstChild.innerText) - parseInt(item1.cells[0].firstChild.innerText)"));            
            if (items.length == 0) return;
            for(var i=items.length-1;i>-1;i--)
            {
              moveSelected(items[i],"up");              
            }
            refreshNoOrder();
        }		
		
		function setNavigationState()
		{
			if (frmResults.tblResults != undefined)
			{
				btnAppend.disabled = ( frmResults.tblResults.rows.length == 0 );
				btnRemove.disabled = ( tblSelected.rows.length == 0 );
			
				tblNoRecords.runtimeStyle.display = ( tblSelected.rows.length == 0 ? "" : "none" );
			}
		}
		
		//单击组织架构树
		function myQuery()
		{
			findValue.value="";
			search();
		}
		
		//单击查找按钮
		function search()
		{
			var oTr = appGridTree.selectedRow;
			if(oTr==undefined || oTr=="undefined") return;

			var url = "map_selectUserData.aspx";
			url += window.location.search;
			url += "&Mode=" + _mode;
			url += "&type=" + oTr.type;
			url += "&guid=" + oTr.oid;
			url += "&searchvalue=" + URLEncode(findValue.value);
			frmResults.location.href = url;
		}
	</script>
</head>

<body style="margin:10px">
		<table cellspacing="0" cellpadding="0" width="100%" height="100%">
			<tr height="30px">
				<td class="search">
					<table width="100%" cellpadding="2" cellspacing="0">
						<tr>
							<td noWrap width="60px"><b style="color:#666666;">查找:</b></td>
							<td><input maxlength="95%" onkeydown="findValueKeyDown()" tabindex="2" type="text" id="findValue" style="width:100%;font-size:9pt;border:1px solid #7b9ebd;"></td>
							<td width="100px"><button disabled="true" tabindex="3" id="btnGo" onclick="search();" title="查找记录">查找</button></td>
						</tr>
						<tr><td style="height:10px;font-size:1px;border-bottom:2px inset #ffffff;" colspan=3>&nbsp;</td></tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table height="100%" width="100%" id="tblFind" cellpadding="0" cellspacing="0" style="table-layout:fixed">
						<tr height="20px">
							<td width="200px">组织架构:</td>
							<td width="5px"></td>
							<td width="150px">所有成员:</td>
							<td width="40px">&nbsp;</td>
							<td width="150px">已选成员:&nbsp;<span  onclick="moveUp()" style="cursor:hand" title="上移选中成员"><img src="/MyWorkflow/images/MoveUP_16_blue.gif" alt="上移" />上移</span>&nbsp;<span  onclick="moveDown()" style="cursor:hand" title="下移选中成员"><img src="/MyWorkflow/images/MoveDown_16_blue.gif" alt="上移"/>下移</span></td>
						</tr>
						<tr>
							<td rowspan=2 valign="top">
								<cnt:AppGridTree id="appGridTree" runat="server" filter="<filter />"  xml="map_selectUserSingle.xml" />
							</td>
							<td></td>
							<td colspan=3 height="3px"></td>
						</tr>
						<tr height="100%">
							<td></td>
							<td>
								<iframe scrolling="no" tabindex="4" class="results" onreadystatechange="resultsReady()" id="frmResults" src="map_selectUserData.aspx"></iframe>
							</td>
							
							<td  align="center">
								<button disabled="true" tabindex="5" id="btnAppend" style="width: 35px;" onclick="appendSelected()" title="添加选中记录">&gt;&gt;</button>
								<p>
								<button disabled="true" tabindex="6" id="btnRemove" style="width: 35px;" onclick="removeSelected();" title="移除选中记录">&lt;&lt;</button>
							</td>
							<td>
								<div id="rtnObjList" class="objects">
									<table hidefocus="true" tabindex="7" id="tblSelected" cellpadding="2" cellspacing="0" width="100%" onclick="clickItem( this )" ondblclick="removeSelected()"  onkeydown="listKeyDown(this)"></table>
									
									<table class="inlineMsg" id="tblNoRecords">
										<tr>
											<td class="inlineMsg" align="center">没有记录被选中。</td>
										</tr>
									</table>
								</div>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr><td style="height:10px;font-size:1px;border-bottom:2px inset #ffffff;">&nbsp;</td></tr>
			<tr height="40">
					<td class="buttons">
						<button style="WIDTH:70px" onclick="applychanges()" id="btnOk" type="button">确 定</button>&nbsp;&nbsp;
						<button style="WIDTH:70px" onclick="parent.window.close();" type="button">取 消</button>
					</td>
				</tr>
		</table>

</body>
</html>
